<?php
class Quanly extends Model
{
    public function __construct()
    {
        parent::__construct('canbo');
    }

    public function getListCanbo($keyword)
    {
        $sql = <<< SQL
SELECT cb.cb_id, cb_hoten, dv.dv_ten AS cb_donvi
FROM canbo AS cb LEFT OUTER JOIN cbgiangday AS cbgd ON cb.cb_id = cbgd.cb_id
	LEFT OUTER JOIN bomon AS bm ON cbgd.bm_id = bm.bm_id
	LEFT OUTER JOIN cbhanhchinh AS cbhc ON cb.cb_id = cbhc.cb_id
	LEFT OUTER JOIN donvi AS dv ON bm.dv_id = dv.dv_id OR cbhc.dv_id = dv.dv_id
WHERE
   (cb.cb_id LIKE :keyword
   OR CONVERT(cb.cb_hoten USING UTF8) LIKE :keyword
   OR CONVERT(dv.dv_ten USING UTF8) LIKE :keyword)
   AND cb_trangthai = 1
SQL;
        return $this->_db->run($sql, array('keyword' => "%{$keyword}%"));
    }
}